/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CdDetalhar.java
 *
 * Created on 29/10/2011, 22:33:42
 */

package br.com.beethoven.ui;

import br.com.beethoven.model.entidade.vo.CD_VO;
import br.com.beethoven.model.entidade.vo.MusicaVO;
import br.com.beethoven.model.fachada.impl.GerenciarCdFacade;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Jusabe
 */
public class CdDetalhar extends javax.swing.JFrame {

    /** Creates new form CdDetalhar */
    public CdDetalhar() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nomeDetalhar = new javax.swing.JLabel();
        bandaDetalhar = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaMusicasDescricao = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Nome:");

        jLabel2.setText("Banda:");

        nomeDetalhar.setText("jLabel3");

        bandaDetalhar.setText("jLabel4");

        tabelaMusicasDescricao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Musicas do Album"
            }
        ));
        jScrollPane1.setViewportView(tabelaMusicasDescricao);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nomeDetalhar)
                    .addComponent(bandaDetalhar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nomeDetalhar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(bandaDetalhar))
                .addContainerGap(245, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(14, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CdDetalhar().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bandaDetalhar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel nomeDetalhar;
    private javax.swing.JTable tabelaMusicasDescricao;
    // End of variables declaration//GEN-END:variables

    void preencherDetalharCD(CD_VO get) {
        nomeDetalhar.setText(get.getNome());
        bandaDetalhar.setText(get.getBanda().getNome());
       preencherTabelarMusicas(get);
    }

    public void preencherTabelarMusicas(CD_VO _cd){
        GerenciarCdFacade fachadaCdFacade = new GerenciarCdFacade();
        List<MusicaVO> listaMusicas;

            listaMusicas = fachadaCdFacade.getMinhasMusicas(_cd);
            Vector<String> tableHeaders = new Vector<String>();
        Vector tableData = new Vector();
        tableHeaders.add("Musicas do CD");

        for(int i=0;i<listaMusicas.size();i++) {
            Vector<Object> oneRow = new Vector<Object>();
            boolean add = oneRow.add(listaMusicas.get(i).getNome());
            tableData.add(oneRow);
        }
        tabelaMusicasDescricao.setModel(new DefaultTableModel(tableData, tableHeaders));

    }

}
